package ribbon.consumer.utils;

import com.xylink.config.SDKConfigMgr;
import com.xylink.config.SignatureVersion;
import com.xylink.model.SdkMeeting;
import com.xylink.sdk.SdkMethodV2;
import com.xylink.util.Result;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ribbon.consumer.config.XylinkConf;

import javax.annotation.PostConstruct;
import java.util.Base64;
import java.util.Map;

@Component
public class XylinkRequestUtil {

    @Autowired
    private XylinkConf xylinkConf;



    public SdkMeeting getMeetingUrl(Map<String,String> paramMap) throws Exception {
//        SDKConfigMgr.initSDKConfig(xylinkConf.getApi_host(), xylinkConf.getClient_id(), xylinkConf.getClient_secret(), xylinkConf.getEnterprise_id(), SignatureVersion.Signature_3_0);

        String createMeetingUrl=Constants.createMeeting+xylinkConf.getEnterprise_id();
        Result<SdkMeeting> result1 = SdkMethodV2.sdkPost(createMeetingUrl, paramMap, SdkMeeting.class);
        if (result1.isSuccess()) {
            SdkMeeting data = result1.getData();
            // 获取Base64编码器
            Base64.Encoder encoder = Base64.getEncoder();
            // 将字符串转换为字节数组，然后使用Base64编码器进行编码
            String encodedString = encoder.encodeToString(data.getControlPassword().getBytes());
            System.out.println("控制密码===原始字符串：" + data.getControlPassword());
            System.out.println("控制密码===Base64编码后的字符串：" + encodedString);

            String meetingNumberString = encoder.encodeToString(data.getMeetingNumber().getBytes());

            System.out.println("控制密码===会议编号字符串：" + data.getMeetingNumber());
            System.out.println("控制密码===会议编号Base64编码后的字符串：" + meetingNumberString);
            return data;
        }else {
            System.out.println(result1);
            return null;
        }
    }

}
